package com.shell.governor.security.user.util;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.shell.bee.cache.Cache;
import com.shell.bee.cache.CacheBuilder;

public class SecurityCodeUtil {
	private static Cache<String, String> SREC_CACHE;

	public static String setCode() {
		if (SREC_CACHE == null) {
			SREC_CACHE = CacheBuilder.newBuilder().build();
		}
		String code = SystemUtil.getUUID();

		SREC_CACHE.put(code, code, 60);

		return code;
	}

	public static boolean checkCode(String code) {
		if (StringUtil.emptyAndNull(code)) {
			return false;
		}
		String checkCode = (String) SREC_CACHE.get(code);
		return code.equals(checkCode);
	}

	public static String getCode(String code) {
		return (String) SREC_CACHE.get(code);
	}
}
